﻿@using Isaac.Joy.Identity.Module
@using Isaac.Joy.WebHelper
@model Isaac.Joy.Identity.Web.DtCms.Models.UserViewModel
@{
    ViewBag.Title = "修改个人资料";
    Layout = Url.BundleContent("~/Views/Shared/_Layout.cshtml");
    var genders = EnumExtentions.ToCollection<Gender>();
}
<div id="mainform">
    <!--导航栏-->
    <div class="location">
        <a href="javascript:history.back(-1);" class="back"><i></i><span>返回上一页</span></a>
        <a class="home"><i></i><span>控制面板</span></a>
        <i class="arrow"></i>
        <span>修改个人资料</span>
    </div>
    <div class="line10"></div>
    <!--/导航栏-->

    <!--内容-->
    <div class="content-tab-wrap">
        <div id="floatHead" class="content-tab">
            <div class="content-tab-ul-wrap">
                <ul>
                    <li><a href="javascript:;" onclick="tabs(this);" class="selected">修改个人资料</a></li>
                </ul>
            </div>
        </div>
    </div>

    <div class="tab-content">
        <dl>
            <dt>用户名</dt>
            <dd>
                <input type="text" id="txtAccount" value="@Model.User.Account" disabled="disabled" class="input normal" datatype="*2-200" sucmsg=" " />
            </dd>
        </dl>
        <dl>
            <dt>邮箱账号</dt>
            <dd>
                <input type="text" id="txtEmail" value="@Model.User.Email" class="input normal" datatype="e" ignore="ignore" sucmsg=" " />
                <span class="Validform_checktip">*取回密码时用到</span></dd>
        </dl>
        <dl>
            <dt>用户昵称</dt>
            <dd>
                <input type="text" id="txtNickName" value="@Model.User.NickName" class="input normal" />
            </dd>
        </dl>
        <dl>
            <dt>用户性别</dt>
            <dd>
                <div class="rule-multi-radio">
                    <span id="rblGender">
                        @foreach (var key in genders.Keys)
                        {
                            if (Model.User.Gender.GetDisplay() == key.ToString())
                            {
                            <input id="rblGender_@genders[key.ToString()]" type="radio" name="rblGender" value="@genders[key.ToString()]" checked="checked" /><label for="rblGender_@genders[key.ToString()]">@key</label>
                            }
                            else
                            {
                            <input id="rblGender_@genders[key.ToString()]" type="radio" name="rblGender" value="@genders[key.ToString()]"/><label for="rblGender_@genders[key.ToString()]">@key</label>
                            }
                        }
                    </span>
                </div>
            </dd>
        </dl>
        <dl>
            <dt>生日日期</dt>
            <dd>
                <div class="input-date">
                    <input type="text" id="txtBirthday" value="@String.Format("{0:yyyy-MM-dd}", Model.User.Birthday)" class="input date" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" datatype="/^\s*$|^\d{4}\-\d{1,2}\-\d{1,2}$/" errormsg="请选择正确的日期" sucmsg=" " />
                    <i>日期</i>
                </div>
            </dd>
        </dl>
        <dl>
            <dt>手机号码</dt>
            <dd>
                <input type="text" id="txtMobile" value="@Model.User.Mobile" class="input normal" />
                <span class="Validform_checktip"></span></dd>
        </dl>
        <dl>
            <dt>电话号码</dt>
            <dd>
                <input type="text" id="txtTel" value="@Model.User.Tel" class="input normal" /></dd>
        </dl>
        <dl>
            <dt>QQ号码</dt>
            <dd>
                <input type="text" id="txtQQ" value="@Model.User.QQ" class="input normal" /></dd>
        </dl>
        <dl>
            <dt>通讯地址</dt>
            <dd>
                <input type="text" id="txtAddress" value="@Model.User.Address" class="input normal" /></dd>
        </dl>
    </div>
    <!--/内容-->

    <!--工具栏-->
    <div class="page-footer">
        <div class="btn-list">
            <input type="hidden" id="Userid" value="@Model.User.Id" />
            <input type="button" value="提交保存" id="btnSubmit" class="btn" />
        </div>
        <div class="clear"></div>
    </div>
    <!--/工具栏-->
</div>
@section scripts{
    <script type="text/javascript">
        $(function () {
            var mainform = $("#mainform").Validform({ tiptype: dtcmstiptype, showAllError: true });

            $("#btnSubmit").click(function () {
                if (!mainform.check()) return false;

                $.ajax({
                    url: '@Url.Action("AjaxEditInfo")',
                    type: "post",
                    data: "User.Account=" + $("#txtAccount").val() +
                        "&User.Email=" + $("#txtEmail").val() +
                        "&User.NickName=" + $("#txtNickName").val() +
                        "&User.Gender=" + $('input:radio[name=rblGender]:checked').val() +
                        "&User.Birthday=" + $("#txtBirthday").val() +
                        "&User.Mobile=" + $("#txtMobile").val() +
                        "&User.Tel=" + $("#txtTel").val() +
                        "&User.QQ=" + $("#txtQQ").val() +
                        "&User.Address=" + $("#txtAddress").val() +
                        "&User.Role.Id=" + $("#ddlRole").val() +
                        "&User.Id=" + $("#Userid").val() +
                        "",
                    processData: false,
                    success: function (response) {
                        var data = JSON.parse(response);
                        errorCode.getMsg(data, function () {
                            if (data.success) {
                                $.dialog.alert('修改成功！', function () {
                                    document.location.reload();
                                }, null, "提示");
                            } else {
                                $.dialog.alert('修改失败！');
                            }
                        }, function (e) {
                            $.dialog.alert(data.msg == '' ? e.msg : data.msg);
                        });
                        return false;
                    }
                });
                return false;
            });
        });
    </script>
}